def ab(n):
    for i in range(3, int(n**0.5)+1):
        if n % i == 0:
            return 0
    return 1
a = input()
if len(a) != 4 or int(a) < 0:
    print(0)
else:
    list = [int(a[0]), int(a[1]), int(a[2]), int(a[3]), int(a[0:2]), int(a[1:3]), int(a[2:4]), int(a[0:3]), int(a[1:4]), int(a)]
    list_ = []
    for n in list:
        if ab(n):
            list_.append(n)
    if list_ != []:
        print(max(list_))
    else:
        print(0)